<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 方式1：直接更换类名 -->
    <svg-icon
      :icon-class="isOn ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="handleToggle"
    />
    <!-- 方式2：准备2套结构 -->
    <!-- <svg-icon
      v-if="isOn"
      class="exit-fullscreen"
      @click="handleToggle"
    />
    <svg-icon
      v-else
      class="fullscreen"
      @click="handleToggle"
    /> -->

  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      // 默认不全屏
      isOn: false
    }
  },
  methods: {
    // 切换全屏
    handleToggle() {
      if (ScreenFull.isEnabled) { // 如果浏览器支持全屏
        // 调用toggle()方法进行切换
        ScreenFull.toggle()
        // 开关取反
        this.isOn = !this.isOn
      } else {
        this.$message.warning('请升级浏览器')
      }
    }
  }
}
</script>
<style scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
